﻿using Lamex.Base;
using Lamex.Library;
using Lamex.mIE.DalServer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.International.Converters.PinYinConverter;
using System.Collections.ObjectModel;
using System.Xml;
using System.IO;
using DevExpress.XtraEditors;
using Lamex.Interface;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using Lamex.Library.CommonClass;
using Lamex.Common;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Lamex.mIE.UI
{
    public partial class Frm_IE_Routing_Part : frmBaseChild
    {
        DataTable dtProc_Type_Ctrl = new DataTable();
        static DataTable dtList = new DataTable();//定义全局清单列表
        static DataTable dtRouting = new DataTable();//定义全局工艺路线组合表
        Lamex.mIE.ucControls.ucShowPic ucShowPicList = null;
        Lamex.mIE.ucControls.ucShowPic_Ref ucShowPicList1 = null;
        bool FLAG = true;//定义参考图纸是否显示
        static int iRow = 0;//定义工艺路线组合默认选择值
        static int iIndex = 0;//定义参考图纸组合所在index
        static string strRef_List = "";//参考图纸工艺路线
        bool FLAG_TYPE = true;//定义按部件还是组件进行维护
        static string PreviousDWG = "";//定义上一条图纸号
        static string PreviousPARTNO = "";//定义上一条部件号      
        public Frm_IE_Routing_Part()
        {
            InitializeComponent();
            rbDWG_NO.Checked = true;
        }
        public Frm_IE_Routing_Part(DataTable dt)
        {
            InitializeComponent();
            rbDWG_NO.Checked = true;
            dtProc_Type_Ctrl = dt;
        }
        public Frm_IE_Routing_Part(string DWG_NO, string Product_Type, string strPart_No)
        {
            InitializeComponent();
            this.txtDWG_No.Text = DWG_NO;
            //this.txtPart_No.Text = strPart_No;
            this.txtProductItem.Text = Product_Type;
            if ((DWG_NO.Trim().Length <= 0 || DWG_NO.Trim() == "NIL") && strPart_No.Trim().Length > 0)
            {
                this.txtPart_No.Text = strPart_No;
                rbPART_NO.Checked = true;
                FLAG_TYPE = false;
                txtPart_No.Enabled = true;
            }
            else
            {
                rbDWG_NO.Checked = true;
                FLAG_TYPE = true;
                txtPart_No.Enabled = false;
            }
        }
        private void Frm_IE_Routing_Part_Load(object sender, EventArgs e)
        {
            try { this.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            InitProductItem(dtProc_Type_Ctrl);
            Init();
            DateEditFormat();
            //rbDWG_NO.Checked = true;
        }
        //控件初始化
        public void Init()
        {
            txtProduct_Desc.ReadOnly = true;
            txtProductFP.ReadOnly = true;
            txtMODEL_NO.ReadOnly = true;
            //txtPart_No.UcReadOnly = true;
            gc_CurrentPart.Controls.Clear();
            gc_ReferencePart.Controls.Clear();
            gc_Routing_Combina.DataSource = new DataTable();
            gcPart_List.DataSource = new DataTable();
            gridControl1.DataSource = new DataTable();
            gridControl2.DataSource = new DataTable();
            SetSize();
            txtProduct_Desc.Text = "";
            txtProductFP.Text = "";
            txtMODEL_NO.Text = "";
            //gc_CurrentPart.Visible = true;
            //gc_ReferencePart.Visible = true;

        }
        //产品类型初始化
        public void InitProductItem(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                this.txtProductItem.Properties.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.txtProductItem.Properties.Items.Add(dt.Rows[i]["PROD_CATEGORY"].ToString());
                }
                txtProductItem.SelectedIndex = 0;
                txtProductItem.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            }
            else
            {
                dt = BaseFactory<IE_Part_TaskList>.Instance.GetProductItem();
                this.txtProductItem.Properties.Items.Clear();
                if (dt.Rows.Count > 0)
                {
                    string[] list = dt.Rows[0]["FIELD_VALUE_OPTION"].ToString().Split(',');
                    foreach (var item in list)
                    {
                        this.txtProductItem.Properties.Items.Add(item);
                    }
                }
            }
        }
        //设置图片按比例分布
        private void Frm_IE_Routing_Part_Resize(object sender, EventArgs e)
        {
            SetSize();

        }
        //设置比例方法
        public void SetSize()
        {
            int wight = this.panelControl3.Width;
            if (FLAG)
            {
                gc_CurrentPart.Width = wight / 2;
                gc_ReferencePart.Width = wight / 2;
            }
            else
            {
                gc_CurrentPart.Width = wight;
            }

        }
        //选择产品类型事件
        private void txtProductItem_UcSelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
                Init();
                txtDWG_No.Text = "";//任务清单跳转时带图纸号，故需在此清空  
                txtPart_No.Text = "";
                GetRouting();
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //清单列表单击
        private void gvPart_List_Click(object sender, EventArgs e)
        {
            try
            {
                ClearInt();
                //获取图纸信息
                int iRow = gvPart_List.FocusedRowHandle;
                string DWG_No = gvPart_List.GetRowCellDisplayText(iRow, "DWG_NO").ToString();//标准图纸号
                string REF_PART = gvPart_List.GetRowCellDisplayText(iRow, "REF_DWG").ToString();//参考图纸号
                string Part_No = gvPart_List.GetRowCellDisplayText(iRow, "PART_NO").ToString();//部件号码
                //显示组件切换
                ShowHideBtn(DWG_No, Part_No);
                if (dtList.Rows.Count <= 0 || dtRouting.Rows.Count <= 0)
                    return;
                //存在勾选工艺路线，移动到下一个图纸号时提示保存
                //得到工艺路线
                int[] iRow_Routing = gv_Routing_Combina.GetSelectedRows();
                if (iRow_Routing.Length > 0)
                {
                    //DevExpress.XtraEditors.XtraMessageBox.Show("没有选择工艺路线！");
                    //return;
                    if (ConfirmDelete() == DialogResult.OK)
                    {
                        //DoSave(null);
                        string strProductType = "";//获取上一工序产品类型
                        DataTable dtProductType = BaseBuildSql.GetDataTableBySql("select PROD_CATEGORY FROM [LamexMESManager].[dbo].[IE_Part_TaskList] where PART_NO='" + PreviousPARTNO + "'");
                        if (dtProductType.Rows.Count > 0)
                            strProductType = dtProductType.Rows[0]["PROD_CATEGORY"].ToString();
                        if (PreviousDWG.Trim().Length > 0 || PreviousPARTNO.Trim().Length > 0)
                            Save(PreviousDWG, PreviousPARTNO, strProductType);
                    }
                }
        
                PreviousDWG = DWG_No;
                PreviousPARTNO = Part_No;
      
                //根据当前部件号的产品类型获取工艺组合
                string strProduct = "";//获取当前工序产品类型
                DataTable dtProduct = BaseBuildSql.GetDataTableBySql("select PROD_CATEGORY FROM [LamexMESManager].[dbo].[IE_Part_TaskList] where PART_NO='" + Part_No + "'");
                if (dtProduct.Rows.Count > 0)
                    strProduct = dtProduct.Rows[0]["PROD_CATEGORY"].ToString();
                if (dtRouting.Select("PRODUCT_TYPE='" + strProduct + "'").Length > 0)
                {
                    DataTable dtRouting_Temp = dtRouting.Select("PRODUCT_TYPE='" + strProduct + "'").CopyToDataTable();
                    RoutingAddNullRow(dtRouting_Temp);
                    if (dtRouting.Rows.Count <= 0)
                        return;
                }
                else
                {
                    return;
                }

                if (FLAG_TYPE)
                {                         
                    //控制是否被锁定
                    string name = Common.GetLock.GetUser(DWG_No).Trim();
                    if (name.Length > 0)
                    {
                        XtraMessageBox.Show("录入员-" + name + "：正在操作此图纸编号");
                        return;
                    }

                    //显示图纸号在界面
                    // txtDWG_No.Text = DWG_No;
                    //显示描述在界面
                    if (DWG_No.Length > 0)
                    {
                        DataRow[] dr_Desc = dtList.Select("DWG_NO='" + DWG_No + "'");
                        if (dr_Desc.Length > 0)
                        {
                            txtProduct_Desc.Text = dr_Desc[0]["CN_DESC"].ToString();
                            txtMODEL_NO.Text = dr_Desc[0]["MODEL_NO"].ToString();
                            txtProductFP.Text= dr_Desc[0]["PRODUCT_ALLOCATION"].ToString();
                        }
                    }
                    else
                    {
                        DataRow[] dr_Desc = dtList.Select("PART_NO='" + Part_No + "'");
                        if (dr_Desc.Length > 0)
                        {
                            txtProduct_Desc.Text = dr_Desc[0]["CN_DESC"].ToString();
                            txtMODEL_NO.Text = dr_Desc[0]["MODEL_NO"].ToString();
                            txtProductFP.Text = dr_Desc[0]["PRODUCT_ALLOCATION"].ToString();
                        }
                    }
                    //解锁当前录入员的操作图纸
                    Common.GetLock.UnLock();

                    //点击即锁定-当前图纸
                    Common.GetLock.LockUser(DWG_No);                 

                    //显示工艺路线组合
                    txtQuickly.Text = "";//清空
                    // dtRouting = Common.GetDWG_List.Dwg_List("IE_Routing_Combination", "ROUTING_DESC", " and PRODUCT_TYPE='" + txtProductItem.Text + "'");
                    gc_Routing_Combina.DataSource = dtRouting;


                    //如果存在工艺路线，则显示
                    string sql_Routing = @"select distinct DWG_NO,GROUP_CODE FROM [LamexMESManager].[dbo].[IE_Part_Routing]
                                    where DWG_NO='" + DWG_No + "'";
                    DataTable dtRouting_Temp1 = BaseBuildSql.GetDataTableBySql(sql_Routing);
                    if (dtRouting_Temp1.Rows.Count > 0)
                    {
                        string strDWG_List = dtRouting.Select("GROUP_CODE='" + dtRouting_Temp1.Rows[0]["GROUP_CODE"].ToString() + "'").CopyToDataTable().Rows[0]["ROUTING_DESC"].ToString();
                        DataRow[] rows = dtRouting.Select("ROUTING_DESC='" + strDWG_List + "'");
                        if (rows.Length > 0)
                        {
                            //自动勾选工艺路线
                            iIndex = dtRouting.Rows.IndexOf(rows[0]);
                            gv_Routing_Combina.SelectRow(iIndex);
                            //定位至焦点行
                            GetFoucuseRowHandle(strDWG_List);
                        }
                    }
                    else
                    {
                        //如果参考图纸不为空，获得参考图纸的工艺路线
                        if (!string.IsNullOrEmpty(REF_PART))
                        {

                            DataTable dt_REF = Common.GetDWG_List.Dwg_List("IE_Routing_Combination C  JOIN IE_Part_Routing R ON R.GROUP_CODE=C.GROUP_CODE",
                                " C.GROUP_CODE,C.ROUTING_DESC ",
                                " and R.DWG_NO='" + REF_PART + "' ");
                            if (dt_REF.Rows.Count > 0)
                            {
                                strRef_List = dt_REF.Rows[0]["ROUTING_DESC"].ToString();
                            }
                            if (strRef_List.Length > 0)
                            {
                                DataRow[] rows = dtRouting.Select("ROUTING_DESC='" + strRef_List + "'");
                                if (rows.Length > 0)
                                {
                                    iIndex = dtRouting.Rows.IndexOf(rows[0]);
                                    gv_Routing_Combina.SelectRow(iIndex);
                                    //定位至焦点行
                                    GetFoucuseRowHandle(strRef_List);
                                }
                            }
                        }
                    }

                    ////根据图纸号获取产品类型，因为不同的产品类型图纸路径不一致
                    //string sql_ProductType = @" select distinct PROD_CATEGORY from [dbo].[IE_Part_TaskList] where DWG_NO='" + DWG_No + "'";
                    //DataTable dt_ProductTemp = BaseBuildSql.GetDataTableBySql(sql_ProductType);
                    //显示图片           
                    var listPic = Common.GetShowPic.ShowPic_STD(txtProductItem.Text.Trim(), DWG_No, REF_PART, Part_No);
                    //标准图纸
                    if (listPic.Item1.Count > 0)
                    {
                        ucShowPicList = new ucControls.ucShowPic();
                        ucShowPicList.LoadImageList(listPic.Item1);
                        //ucShowPicList.LoadImageList_Size(listPic.Item1, gc_CurrentPart.Width, gc_CurrentPart.Height);
                        ucShowPicList.Dock = DockStyle.Fill;
                        gc_CurrentPart.Controls.Add(ucShowPicList);
                    }
                    //参考图纸
                    if (listPic.Item2.Count > 0)
                    {
                        ucShowPicList1 = new ucControls.ucShowPic_Ref();
                        ucShowPicList1.LoadImageList(listPic.Item2);
                        ucShowPicList1.Dock = DockStyle.Fill;
                        gc_ReferencePart.Controls.Add(ucShowPicList1);
                    }
                    else
                    {
                        gc_ReferencePart.Visible = false;
                        int wight = this.panelControl3.Width;
                        gc_CurrentPart.Width = wight;
                        FLAG = false;
                    }
                  
                 
                }
                else
                {
                    if (Part_No.Length <= 0)
                        return;
                    string REF_MATNO = gvPart_List.GetRowCellDisplayText(iRow, "REF_MAT").ToString().Trim();//部件物料

                    //控制是否被锁定
                    string name = Common.GetLock.GetUser(Part_No).Trim();
                    if (name.Length > 0)
                    {
                        XtraMessageBox.Show("录入员-" + name + "：正在操作此图纸编号");
                        return;
                    }
                    //解锁当前录入员的操作图纸
                    Common.GetLock.UnLock();

                    //点击即锁定-当前图纸
                    Common.GetLock.LockUser(Part_No);

                    //显示描述在界面                
                    DataRow[] dr_Desc = dtList.Select("PART_NO='" + Part_No + "'");
                    if (dr_Desc.Length > 0)
                    {
                        txtProduct_Desc.Text = dr_Desc[0]["CN_DESC"].ToString();
                        txtMODEL_NO.Text = dr_Desc[0]["MODEL_NO"].ToString();
                        txtProductFP.Text = dr_Desc[0]["PRODUCT_ALLOCATION"].ToString();
                    }                 
                    txtQuickly.Text = "";//清空
                    // dtRouting = Common.GetDWG_List.Dwg_List("IE_Routing_Combination", "ROUTING_DESC", " and PRODUCT_TYPE='" + txtProductItem.Text + "'");
                    gc_Routing_Combina.DataSource = dtRouting;//先赋值，不然定位不到

                    //如果存在工艺路线，则显示
                    string sql_Routing = @"select distinct DWG_NO,GROUP_CODE FROM [LamexMESManager].[dbo].[IE_Part_Routing]
                                    where PART_NO='" + Part_No + "'";
                    DataTable dtRouting_Temp1 = BaseBuildSql.GetDataTableBySql(sql_Routing);
                    if (dtRouting_Temp1.Rows.Count > 0)
                    {
                        string strDWG_List = dtRouting.Select("GROUP_CODE='" + dtRouting_Temp1.Rows[0]["GROUP_CODE"].ToString() + "'").CopyToDataTable().Rows[0]["ROUTING_DESC"].ToString();
                        DataRow[] rows = dtRouting.Select("ROUTING_DESC='" + strDWG_List + "'");
                        if (rows.Length > 0)
                        {
                            //自动勾选工艺路线
                            iIndex = dtRouting.Rows.IndexOf(rows[0]);
                            gv_Routing_Combina.SelectRow(iIndex);
                            //定位至焦点行
                            GetFoucuseRowHandle(strDWG_List);
                        }
                    }
                    else
                    {
                        //如果参考物料不为空，获得参考物料的工艺路线
                        if (!string.IsNullOrEmpty(REF_MATNO))
                        {

                            DataTable dt_REF = Common.GetDWG_List.Dwg_List("IE_Routing_Combination C  JOIN IE_Part_Routing R ON R.GROUP_CODE=C.GROUP_CODE",
                                " C.GROUP_CODE,C.ROUTING_DESC ",
                                " and R.PART_NO='" + REF_MATNO + "' ");
                            if (dt_REF.Rows.Count > 0)
                            {
                                strRef_List = dt_REF.Rows[0]["ROUTING_DESC"].ToString();
                            }
                            if (strRef_List.Length > 0)
                            {
                                DataRow[] rows = dtRouting.Select("ROUTING_DESC='" + strRef_List + "'");
                                if (rows.Length > 0)
                                {
                                    iIndex = dtRouting.Rows.IndexOf(rows[0]);
                                    gv_Routing_Combina.SelectRow(iIndex);
                                    //定位至焦点行
                                    GetFoucuseRowHandle(strRef_List);
                                }
                            }
                        }
                    }


                    DataTable dt = new DataTable();
                    DataTable dt_Ref = new DataTable();
                    string sql = "";
                    string sql_Ref = "";
                    int iBOM_STD = 0,iBOM_SJ=0;
                    if (Part_No.Substring(1, 2) == "96")
                    {
                        sql = @"SELECT     
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO]    
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR]
  where MATERIAL_NO='" + Part_No + "'";
                    }
                    else
                    {
                        sql = @"SELECT 
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO] 
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_STD]
where MATERIAL_NO='" + Part_No + "' and ISNULL(Version,'')='" + cbBOM.Text.Trim() + "' ";
                        if (strProduct == "Laminate" || strProduct == "Panel")
                        {
                            DataTable dtTemp = BaseBuildSql.GetDataTableBySql(sql);
                            if (dtTemp.Rows.Count <= 0)
                            {
                                sql = @"SELECT 
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO] 
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_STD]
where MATERIAL_NO='" + Part_No + "' and ISNULL(Version,'')='" + cbBOM.Text.Trim() + "' ";
                                DataTable dtTemp1 = BaseBuildSql.GetDataTableBySql(sql);
                                if (dtTemp1.Rows.Count <= 0)
                                {
                                    iBOM_STD++;
                                    //ClearInt();
                                    //DevExpress.XtraEditors.XtraMessageBox.Show("当前物料BOM表无数据，请确认！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    //return;
                                }
                            }
                        }
                    }
                    //参考物料显示
                    if (REF_MATNO.Length > 0 && REF_MATNO != "NIL")
                    {
                        if (REF_MATNO.Substring(1, 2) == "96")
                        {
                            sql_Ref = @"SELECT     
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO]    
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR]
  where MATERIAL_NO='" + REF_MATNO + "'";
                        }
                        else
                        {
                            sql_Ref = @"SELECT 
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO] 
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_STD]
where MATERIAL_NO='" + REF_MATNO + "' and  ISNULL(Version,'')='" + cbBOM.Text.Trim() + "'";
                            if (strProduct == "Laminate" || strProduct == "Panel")
                            {
                                DataTable dtTemp = BaseBuildSql.GetDataTableBySql(sql_Ref);
                                if (dtTemp.Rows.Count <= 0)
                                {
                                    sql_Ref = @"SELECT 
       [COMPONENT]
      ,[DESCRIBES]   
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO] 
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_STD]
where MATERIAL_NO='" + REF_MATNO + "' and ISNULL(Version,'')='" + cbBOM.Text.Trim() + "' ";
                                    DataTable dtTemp1 = BaseBuildSql.GetDataTableBySql(sql_Ref);
                                    if (dtTemp1.Rows.Count <= 0)
                                    {
                                        iBOM_SJ++;
                                        //ClearInt();
                                        //DevExpress.XtraEditors.XtraMessageBox.Show("当前参考物料BOM表无数据，请确认！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        //return;
                                    }
                                }
                            }
                            dt_Ref = BaseBuildSql.GetDataTableBySql(sql_Ref);
                        }
                    }
                    else
                    {
                        gc_ReferencePart.Visible = false;
                        int wight = this.panelControl3.Width;
                        gc_CurrentPart.Width = wight;
                        FLAG = false;
                    }
                    if (iBOM_STD > 0 && iBOM_SJ > 0)
                    {
                        ClearInt();
                        DevExpress.XtraEditors.XtraMessageBox.Show("当前物料BOM表无数据，请确认！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    dt = BaseBuildSql.GetDataTableBySql(sql);
                    gridControl1.DataSource = dt;
                    gridControl2.DataSource = dt_Ref;
                    //gridView1.BestFitColumns();
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView2.OptionsView.ColumnAutoWidth = false;
                    this.gridView1.BestFitColumns();
                    this.gridView2.BestFitColumns();
                    gc_CurrentPart.Controls.Add(gridControl1);
                    gc_ReferencePart.Controls.Add(gridControl2);
                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
            }
        }
        public void ClearInt()
        {
            SetSize();
            btnChange.Enabled = false;
            gc_ReferencePart.Visible = true;
            gc_CurrentPart.Visible = true;
            FLAG = true;
            gc_ReferencePart.Controls.Clear();
            gc_CurrentPart.Controls.Clear();
            gc_Routing_Combina.DataSource = new DataTable();
            strRef_List = "";//每次双击初始化参考图纸工艺路线
            iIndex = 0;//每次双击初始化参考图纸工艺路线index 
        }
        public void ShowHideBtn(string DwgNo, string PartNo)
        {
            //卡控组件部件切换按钮
            if (DwgNo.Length > 3 && DwgNo.Substring(0, 3) == "396")
            {
                btnChange.Enabled = true;
            }
            if (PartNo.Length > 3 && PartNo.Substring(0, 3) == "396")
            {
                btnChange.Enabled = true;
            }
        }
        //保存
        public override void DoSave(IButtonInfo sender)
        {
            //得到图纸编号/部件号
            int iRow_DWG = gvPart_List.FocusedRowHandle;
            string DWG_No = gvPart_List.GetRowCellDisplayText(iRow_DWG, "DWG_NO").ToString();//标准图纸号
            string Part_No = gvPart_List.GetRowCellDisplayText(iRow_DWG, "PART_NO").ToString();//部件号码
            string strProductType = "";//获取产品类型
            DataTable dtProductType = BaseBuildSql.GetDataTableBySql("select PROD_CATEGORY FROM [LamexMESManager].[dbo].[IE_Part_TaskList] where PART_NO='" + Part_No + "'");
            if (dtProductType.Rows.Count > 0)
                strProductType = dtProductType.Rows[0]["PROD_CATEGORY"].ToString();
            Save(DWG_No, Part_No, strProductType);
        }
        public void Save(string DWG_No, string Part_No, string strProductType)
        {
            try
            {
                #region 按钮权限
                if (!BuildSqlHelper.IsExistList("IE_Part_Routing", "LamexMESManager")) return;
                #endregion

                DataTable dtNew = Common.GetTable.GetTable_Routing();//动态保存表
                if (FLAG_TYPE)
                {

                    if (string.IsNullOrEmpty(DWG_No)||DWG_No=="NIL")
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("没有选择图纸编号或图纸号为NIL！");
                        return;
                    }
                    //得到该图纸的所有部件信息
                    DataTable dt = Common.GetDWG_List.Dwg_List("IE_Part_TaskList T LEFT JOIN IE_Part_Routing R ON T.DWG_NO=R.DWG_NO",
                        "DISTINCT T.DWG_NO,T.PART_NO",
                        " and T.DWG_NO='" + DWG_No + "' ");//and  ISNULL(T.ROUTING_FLAG,'')!='1'
                    if (dt.Rows.Count <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("在表【IE_Part_TaskList】和【IE_Part_Routing】没有查询到该图纸编号的任何信息！");
                        return;
                    }

                    //得到工艺路线
                    int[] iRow_Routing = gv_Routing_Combina.GetSelectedRows();
                    if (iRow_Routing.Length <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("没有选择工艺路线！");
                        return;
                    }
                    if (iRow_Routing.Length >= 2)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("只能选择一条工艺路线！");
                        return;
                    }
                    DataRow row = gv_Routing_Combina.GetDataRow(iRow_Routing[0]);
                    string Routing = row[3].ToString();//工艺路线
                    #region //2019-11-25 cancel
                    //得到工序代码-判断是否存在
                    //DataTable dt_ProcessCode = Common.GetDWG_List.Dwg_List("IE_WorkCenter_Definition", "PROCESS_CODE,PROCESS_NAME", " ");
                    //string[] Routing_List = Routing.Split('_');
                    //// List<string> list = new List<string>();//获取工序代码列表
                    //string IsNoProcess = "";
                    //foreach (var item in Routing_List)
                    //{
                    //    if (dt_ProcessCode.Select("PROCESS_NAME='" + item + "'").Length <= 0)
                    //    {
                    //        IsNoProcess = IsNoProcess + item + "、";
                    //        continue;
                    //    }
                    //    //list.Add(item);                  
                    //}
                    //if (IsNoProcess.Length > 0)
                    //{
                    //    DevExpress.XtraEditors.XtraMessageBox.Show("工序表【IE_WorkCenter_Definition】无【" + IsNoProcess.Substring(0, IsNoProcess.Length - 1) + "】工序,请先维护，谢谢！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //    return;
                    //}
                    #endregion
                    //数据插入周期表
                    string sql_cycle = @"select DEFAULT_CYCLE from [LamexMESManager].[dbo].[IE_Routing_Combination] where GROUP_CODE='" + row[2].ToString() + "'";
                    DataTable dt_cycle = BaseBuildSql.GetDataTableBySql(sql_cycle);
                    if (dt_cycle.Rows.Count > 0)
                    {
                        string str_cycle = dt_cycle.Rows[0]["DEFAULT_CYCLE"].ToString().Trim().Length > 0 ?
                            dt_cycle.Rows[0]["DEFAULT_CYCLE"].ToString().Trim() : "NULL"; 
                        //if (str_cycle.Length > 0)
                        //{
                        //获得图纸号的所有部件
                        DataTable dt_PartNoList = BaseBuildSql.GetDataTableBySql("select PART_NO from  [LamexMESManager].[dbo].[IE_Part_TaskList] where DWG_NO='" + DWG_No + "'");
                        if (dt_PartNoList.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt_PartNoList.Rows.Count; i++)
                            {
                                //先删除周期表
                                string sql_delete = @" delete FROM [LamexMESManager].[dbo].[IE_Part_CycleTime] where PART_NO='" + dt_PartNoList.Rows[i]["PART_NO"].ToString() + "'";
                                BaseBuildSql.ExecuteNonQuery(sql_delete);
                                string sql_insert = @" insert into [LamexMESManager].[dbo].[IE_Part_CycleTime](PART_NO,CYCLE_TIME,UPDATE_TIME,UPDATE_USER)
                                                           values('" + dt_PartNoList.Rows[i]["PART_NO"] + "'," + str_cycle + ",getdate(),'" + Lamex.Common.Loginer.CurrentUser.AccountName + "')";
                                BaseBuildSql.ExecuteNonQuery(sql_insert);
                            }
                        }                      
                    }


                    string sql_Size = @"select DISTINCT PROCESS_CODE from IE_Part_FeatureList where DWG_NO='" + DWG_No + "'";
                    DataTable dtTemp = BaseBuildSql.GetDataTableBySql(sql_Size);
                    if (dtTemp.Rows.Count > 0)
                    {
                        if (ConfirmOK() == DialogResult.No)
                            return;
                        //获取已存在的部件特征值         
                        string Sql_Routing_Desc = @"SELECT ROUTING_CODE FROM [LamexMESManager].[dbo].[IE_Routing_Combination] where GROUP_CODE='" + row[2].ToString() + "'";
                        DataTable dtTempCode = BaseBuildSql.GetDataTableBySql(Sql_Routing_Desc);
                        string[] Routing_Code = dtTempCode.Rows[0]["ROUTING_CODE"].ToString().Split('_');
                        List<string> list = new List<string>();
                        List<string> list1 = new List<string>();
                        List<string> list2 = new List<string>();
                        List<string> list3 = new List<string>();
                        StringBuilder s1 = new StringBuilder();
                        for (int i = 0; i < dtTemp.Rows.Count; i++)
                        {
                            list.Add(dtTemp.Rows[i]["PROCESS_CODE"].ToString());
                        }
                        foreach (var item in Routing_Code)
                        {
                            list1.Add(item);
                        }
                        list2 = list.Intersect(list1).ToList();//先取交集
                        list3 = list.Except(list2).ToList();//再去差集，删除
                        if (list3.Count > 0)
                        {
                            s1.AppendFormat(@" AND PROCESS_CODE IN ('{0}')", string.Join("','", list3.ToArray()));
                            string deleteSql_Code = @"delete from IE_Part_FeatureList  where DWG_NO='" + DWG_No + "' " + s1 + " ";
                            BaseBuildSql.ExecuteNonQuery(deleteSql_Code);
                        }
                        string UpdateSql = @"update IE_Part_TaskList set CAL_FLAG='',FEAT_FLAG='' where DWG_NO='" + DWG_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    }
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {

                        DataRow dr = dtNew.NewRow();
                        dr["DWG_NO"] = dt.Rows[i]["DWG_NO"].ToString();
                        dr["PART_NO"] = dt.Rows[i]["PART_NO"].ToString();
                        //dr["SEQUENCE_NO"] = (j + 1) * 10;
                        dr["GROUP_CODE"] = row[2].ToString();//dt_GROUP_CODE.Rows[0]["GROUP_CODE"].ToString();
                        dr["LAST_SAVE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                        dtNew.Rows.Add(dr);

                    }
                    //删除已存在且未上传的数据
                    string DeleteSql = @"delete from IE_Part_Routing where DWG_NO='" + DWG_No + "' ";
                    BaseBuildSql.ExecuteNonQuery(DeleteSql);
                    //如有参考工艺路线，且与当前选择工艺路线不一致时，同时记录保存【参考调整标识】
                    if (!string.IsNullOrEmpty(strRef_List) && Routing != strRef_List)
                    {
                        string UpdateSql = @"update IE_Part_TaskList set REF_FLAG='1' where DWG_NO='" + DWG_No + "' and PROD_CATEGORY!='Panel' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    }
                    //批量插入数据库
                    if (BaseBuildSql.ExcuteInsert(dtNew, "IE_Part_Routing"))
                    {
                        //更新【IE_Part_TaskList】的“工艺路线标识”
                        string UpdateSql = @"update IE_Part_TaskList set ROUTING_FLAG='1' where DWG_NO='" + DWG_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                        // DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtProductItem_UcSelectedValueChanged(null, null);
                        //解锁当前录入员的操作图纸
                        Common.GetLock.UnLock();
                    }
                }

                else
                {
                    if (string.IsNullOrEmpty(Part_No))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("没有选择部件编号！");
                        return;
                    }
                    //得到工艺路线
                    int[] iRow_Routing = gv_Routing_Combina.GetSelectedRows();
                    if (iRow_Routing.Length <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("没有选择工艺路线！");
                        return;
                    }
                    if (iRow_Routing.Length >= 2)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("只能选择一条工艺路线！");
                        return;
                    }
                    DataRow row = gv_Routing_Combina.GetDataRow(iRow_Routing[0]);
                    string Routing_GroupCode = row[2].ToString();//工艺路线简码
                    string Routing = row[3].ToString();//工艺路线描述
                    //得到工序代码-判断是否存在
                    DataTable dt_ProcessCode = Common.GetDWG_List.Dwg_List("IE_WorkCenter_Definition", "PROCESS_CODE,PROCESS_NAME", " ");
                    DataTable dtroutingcode = BaseBuildSql.GetDataTableBySql(" select ROUTING_CODE FROM IE_Routing_Combination where GROUP_CODE='" + Routing_GroupCode + "'");
                    if (dtroutingcode.Rows.Count <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("选择工艺路线不能选择为空！");
                        return;
                    }
                    string RoutingCode = dtroutingcode.Rows[0]["ROUTING_CODE"].ToString();
                    string[] Routing_List = Routing.Split('_');
                    string[] GroupCode_List = RoutingCode.Split('_');
                 
                    //数据插入周期表
                    string sql_cycle = @"select DEFAULT_CYCLE from [LamexMESManager].[dbo].[IE_Routing_Combination] where GROUP_CODE='" + row[2].ToString() + "'";
                    DataTable dt_cycle = BaseBuildSql.GetDataTableBySql(sql_cycle);
                    if (dt_cycle.Rows.Count > 0)
                    {
                        string str_cycle = dt_cycle.Rows[0]["DEFAULT_CYCLE"].ToString().Trim().Length > 0 ?
                             dt_cycle.Rows[0]["DEFAULT_CYCLE"].ToString().Trim() : "NULL";
                        //if (str_cycle.Length > 0)
                        //{
                        //先删除周期表
                        string sql_delete = @" delete FROM [LamexMESManager].[dbo].[IE_Part_CycleTime] where PART_NO='" + Part_No + "'";
                        BaseBuildSql.ExecuteNonQuery(sql_delete);
                        string sql_insert = @" insert into [LamexMESManager].[dbo].[IE_Part_CycleTime](PART_NO,CYCLE_TIME,UPDATE_TIME,UPDATE_USER)
                                                           values('" + Part_No + "'," + str_cycle + ",getdate(),'" + Lamex.Common.Loginer.CurrentUser.AccountName + "')";
                        BaseBuildSql.ExecuteNonQuery(sql_insert);                    
                    }


                    //检查特征表是否存在，若存在则删除相同的工序特征
                    string sql_Size = @"select DISTINCT PROCESS_CODE from IE_Part_FeatureList where PART_NO='" + Part_No + "'";
                    DataTable dtTemp = BaseBuildSql.GetDataTableBySql(sql_Size);
                    if (dtTemp.Rows.Count > 0)
                    {
                        if (ConfirmOK() == DialogResult.No)
                            return;
                        //获取已存在的部件特征值         
                        string Sql_Routing_Desc = @"SELECT ROUTING_CODE FROM [LamexMESManager].[dbo].[IE_Routing_Combination] where GROUP_CODE='" + row[2].ToString() + "'";
                        DataTable dtTempCode = BaseBuildSql.GetDataTableBySql(Sql_Routing_Desc);
                        string[] Routing_Code = dtTempCode.Rows[0]["ROUTING_CODE"].ToString().Split('_');
                        List<string> list = new List<string>();
                        List<string> list1 = new List<string>();
                        List<string> list2 = new List<string>();
                        List<string> list3 = new List<string>();
                        StringBuilder s1 = new StringBuilder();
                        for (int i = 0; i < dtTemp.Rows.Count; i++)
                        {
                            list.Add(dtTemp.Rows[i]["PROCESS_CODE"].ToString());
                        }
                        //foreach (var item in Routing_Code)
                        //{
                        //    list1.Add(item);
                        //}
                        //list2 = list.Intersect(list1).ToList();//取交集
                        //list3 = list.Except(list2).ToList();//再去差集，删除
                        if (list.Count > 0)
                        {
                            s1.AppendFormat(@" AND PROCESS_CODE IN ('{0}')", string.Join("','", list.ToArray()));
                            string deleteSql_Code = @"delete from IE_Part_FeatureList  where PART_NO='" + Part_No + "' " + s1 + " ";
                            BaseBuildSql.ExecuteNonQuery(deleteSql_Code);
                        }
                        string UpdateSql = @"update IE_Part_TaskList set CAL_FLAG='',FEAT_FLAG='' where PART_NO='" + Part_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    }
                    //如有参考工艺路线，且与当前选择工艺路线不一致时，同时记录保存【参考调整标识】
                    if (!string.IsNullOrEmpty(strRef_List) && Routing != strRef_List)
                    {
                        string UpdateSql = @"update IE_Part_TaskList set REF_FLAG='1' where PART_NO='" + Part_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    }
                    //针对seating，若有更改工艺路线且尺寸参数存在，则取消尺寸标识
                    if (strProductType == "Seating")
                    {
                        string Parm_sql = @" SELECT GROUP_CODE FROM [LamexMESManager].[dbo].[IE_Part_Routing] WHERE  PART_NO='" + Part_No + "' ";
                        DataTable dt_Parm = BaseBuildSql.GetDataTableBySql(Parm_sql);
                        if (dt_Parm.Rows.Count > 0)
                        {
                            string sql_Temp = @"SELECT ROUTING_DESC FROM [LamexMESManager].[dbo].[IE_Routing_Combination] WHERE GROUP_CODE='" + dt_Parm.Rows[0]["GROUP_CODE"].ToString() + "'";
                            DataTable dt_Temp = BaseBuildSql.GetDataTableBySql(sql_Temp);
                            if (dt_Temp.Rows.Count > 0)
                            {
                                if (Routing != dt_Temp.Rows[0]["ROUTING_DESC"].ToString())
                                {
                                    //取消尺寸参数标识
                                    string UpdateSql = @"update IE_Part_TaskList set PARM_FLAG='' where PART_NO='" + Part_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                                    BaseBuildSql.ExecuteNonQuery(UpdateSql);
                                }
                            }

                        }
                    }
                    //////测试专用
                    //Part_No = "3033200131";
                    //string[] GroupCode_List = "P73_P75".Split('_');

                    //组件工艺路线维护读BOM逻辑只适用Laminate&Panel产品，其它类型只保存工艺路线
                    //增加MCG类型和包含P79的工序 Update by Bill 20191204
                    if (strProductType == "Laminate" || strProductType == "Panel"||strProductType=="MCG")
                    {
                        if (strProductType == "MCG" && !GroupCode_List.Contains("P79"))
                            goto A;
                        //逻辑计算特征值和工时并插入特征表
                        DataTable dtResult = new DataTable();
                        double outRes = 0;
                        string Error_Code = "";
                        foreach (var item in GroupCode_List)
                        {
                            dtResult = Calculate.LGC_VAL_BOM.LGC_VAL_BOM_VALUE_ALL(cbBOM.Text,DWG_No, Part_No, item, "", GroupCode_List, out Error_Code);
                            if (Error_Code.Length > 0)
                            {
                                string DeleteSql1 = @"delete from IE_Part_FeatureList where PART_NO='" + Part_No + "' ";
                                BaseBuildSql.ExecuteNonQuery(DeleteSql1);
                                DevExpress.XtraEditors.XtraMessageBox.Show(Error_Code, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                //当使用参考物料计算时,返回的部件号是参考物料,需要转换
                                if (dtResult.Rows.Count > 0)
                                {
                                    if (dtResult.Rows[0]["PART_NO"].ToString() != Part_No)
                                    {
                                        for (int i = 0; i < dtResult.Rows.Count; i++)
                                        {
                                            dtResult.Rows[i]["PART_NO"] = Part_No;
                                        }
                                    }
                                }
                                if (BaseBuildSql.ExcuteInsert(dtResult, "IE_Part_FeatureList"))
                                {
                                    string UpdateSql = @"update IE_Part_TaskList set FEAT_FLAG='1' where PART_NO='" + Part_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                                    BaseBuildSql.ExecuteNonQuery(UpdateSql);
                                }
                            }
                        }
                    }
                    
                    //删除已存在且未上传的数据
                A: string DeleteSql = @"delete from IE_Part_Routing where PART_NO='" + Part_No + "' ";
                    BaseBuildSql.ExecuteNonQuery(DeleteSql);

                    //批量插入数据库--IE_Part_Routing
                    DataRow dr = dtNew.NewRow();
                    dr["DWG_NO"] = DWG_No;
                    dr["PART_NO"] = Part_No;
                    dr["GROUP_CODE"] = row[2].ToString();//dt_GROUP_CODE.Rows[0]["GROUP_CODE"].ToString();
                    dr["LAST_SAVE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtNew.Rows.Add(dr);

                    if (BaseBuildSql.ExcuteInsert(dtNew, "IE_Part_Routing"))
                    {
                        //更新【IE_Part_TaskList】的“工艺路线标识”
                        string UpdateSql = @"update IE_Part_TaskList set ROUTING_FLAG='1' where PART_NO='" + Part_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                        BaseBuildSql.ExecuteNonQuery(UpdateSql);
                        // DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtProductItem_UcSelectedValueChanged(null, null);
                        //解锁当前录入员的操作图纸
                        Common.GetLock.UnLock();
                    }
                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
            }
        }
        //联动查询     
        private void txtQuickly_UcTextChanged(object sender, EventArgs e)
        {
            if (dtRouting.Rows.Count <= 0)
                return;
            DataTable dtNew = Common.GetTable.GetTable_New();
            if (!string.IsNullOrEmpty(txtQuickly.Text))
            {
                //填充数据到新的Datatable
                // dt = dtRouting.Copy();
                for (int i = 0; i < dtRouting.Rows.Count; i++)
                {

                    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[^a-zA-Z\r\n]+");
                    #region 按拼音首字母检索
                    if (!reg.Match(txtQuickly.Text).Success)
                    {

                        string strName = GetChineseSpell(dtRouting.Rows[i]["ROUTING_DESC"].ToString().ToCharArray()).ToLower();
                        string strTxtName = txtQuickly.Text.ToLower();
                        //根据拼音进行匹配
                        if (strName.Contains(strTxtName) && strName.Substring(0, strTxtName.Length) == strTxtName)
                        {
                            DataRow dr = dtNew.NewRow();
                            dr["SEQUENCE"] = dtRouting.Rows[i]["SEQUENCE"].ToString();
                            dr["GROUP_CODE"] = dtRouting.Rows[i]["GROUP_CODE"].ToString();
                            dr["ROUTING_DESC"] = dtRouting.Rows[i]["ROUTING_DESC"].ToString();
                            dtNew.Rows.Add(dr);
                        }

                    }
                    #endregion
                    #region 按中文检索
                    else
                    {
                        if (dtRouting.Rows[i]["ROUTING_DESC"].ToString().Contains(txtQuickly.Text))
                        {
                            DataRow dr = dtNew.NewRow();
                            dr["SEQUENCE"] = dtRouting.Rows[i]["SEQUENCE"].ToString();
                            dr["GROUP_CODE"] = dtRouting.Rows[i]["GROUP_CODE"].ToString();
                            dr["ROUTING_DESC"] = dtRouting.Rows[i]["ROUTING_DESC"].ToString();
                            dtNew.Rows.Add(dr);
                        }
                    }
                    #endregion

                }
                gc_Routing_Combina.DataSource = dtNew;
            }
            else
            {
                gc_Routing_Combina.DataSource = dtRouting;
            }
        }
        public string GetChineseSpell(char[] list)
        {
            StringBuilder str = new StringBuilder();//定义一个可变长度的字符串
            char[] chs; //定义一个字符数组来接收每个汉字的拼音
            //遍历F_ConnName字段中所有汉字
            foreach (char c in list)
            {
                //验证该汉字是否合法
                if (ChineseChar.IsValidChar(c))
                {
                    ChineseChar CC = new ChineseChar(c);
                    //将该汉字转化为拼音集合
                    ReadOnlyCollection<string> roc = CC.Pinyins;
                    //获取集合中第一个数据即为该汉字的拼音
                    chs = roc[0].ToLower().ToCharArray();
                    //将该汉字的拼音首字母追加到可变字符串中
                    str.Append(chs[0]);
                }
            }
            return str.ToString();
        }
        //工艺路线组合单击
        private void gv_Routing_Combina_Click(object sender, EventArgs e)
        {
            if (gv_Routing_Combina.RowCount < 0) return;
            gv_Routing_Combina.UnselectRow(iRow);
            gv_Routing_Combina.UnselectRow(iIndex);
            iRow = gv_Routing_Combina.FocusedRowHandle;
            gv_Routing_Combina.SelectRow(iRow);

        }
        //导入
        public override void DoImport(IButtonInfo sender)
        {
            #region 按钮权限
            if (!BuildSqlHelper.IsExistList("IE_Part_Routing", "LamexMESManager")) return;
            #endregion
            DevExpress.XtraEditors.XtraMessageBox.Show("未上载数据中，图纸编号+部件编号重复时，原有记录将进行覆盖！\r\n导入标题必须为图纸编号+部件编号+组简码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            OpenFileDialog dlg = new OpenFileDialog();
            DataTable dtEqual = new DataTable();//获取导入文件和数据库未上载标识 图纸号+部件号相同值
            List<string> Temp1 = new List<string>();
            List<string> Temp2 = new List<string>();
            StringBuilder sbFilter1 = new StringBuilder();
            StringBuilder sbFilter2 = new StringBuilder();
            if (DialogResult.OK == dlg.ShowDialog())
            {
                try
                {
                    SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
                    string path = dlg.FileName;
                    //导入EXCEL转换成Table
                    DataTable dtImport = Lamex.Common.ExecelHelper.ExcelToDataTable(path, 1);
                    if (dtImport.Rows.Count <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("导入数据为空！");
                        return;
                    }
                    for (int k = 0; k < dtImport.Rows.Count; k++)
                    {

                        if (string.IsNullOrEmpty(dtImport.Rows[k]["图纸编号"].ToString()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("第" + (k + 1) + "行图纸编号为空值！");
                            return;
                        }
                        if (string.IsNullOrEmpty(dtImport.Rows[k]["部件编号"].ToString()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("第" + (k + 1) + "行部件编号为空值！");
                            return;
                        }
                        if (string.IsNullOrEmpty(dtImport.Rows[k]["组简码"].ToString()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("第" + (k + 1) + "行工序代码为空值！");
                            return;
                        }
                    }
                    //查询数据库表-上载标识不等于1
                    DataTable dt = BaseFactory<IE_Part_Routing>.Instance.GetDataSet().Tables[0];

                    //DataColumn dc3 = new DataColumn("SEQUENCE_NO", typeof(int));
                    //dtImport.Columns.Add(dc3);
                    //int s = 1;
                    for (int i = 0; i < dtImport.Rows.Count; i++)
                    {
                        //    //动态赋值给序号
                        //    if (i == 0)
                        //    {
                        //        dtImport.Rows[i]["SEQUENCE_NO"] = 10;
                        //    }
                        //    else if (dtImport.Rows[i]["图纸编号"].ToString() == dtImport.Rows[i - 1]["图纸编号"].ToString())
                        //    {
                        //        dtImport.Rows[i]["SEQUENCE_NO"] = (s + 1) * 10;
                        //        s++;
                        //    }
                        //    else
                        //    {
                        //        dtImport.Rows[i]["SEQUENCE_NO"] = 10;
                        //        s = 1;
                        //    }
                        //找出未上载的重复值
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            if (dtImport.Rows[i]["图纸编号"].ToString() + dtImport.Rows[i]["部件编号"] ==
                                dt.Rows[j]["DWG_NO"].ToString() + dt.Rows[j]["PART_NO"].ToString())
                            {
                                Temp1.Add(dt.Rows[j]["DWG_NO"].ToString());
                                Temp2.Add(dt.Rows[j]["PART_NO"].ToString());
                            }
                        }
                    }
                    //删除上载标识不等于1的重复项
                    if (Temp1.Count > 0 && Temp2.Count > 0)
                    {
                        sbFilter1.AppendFormat(@" AND DWG_NO IN ('{0}')", string.Join("','", Temp1.ToArray()));
                        sbFilter2.AppendFormat(@" AND PART_NO IN ('{0}')", string.Join("','", Temp2.ToArray()));

                        string sqlDel = @"Delete  FROM IE_Part_Routing where 1=1  " + sbFilter1 + " " + sbFilter2 + "  ";
                        int n = BaseBuildSql.ExecuteNonQuery(sqlDel);
                    }
                    //添加导入时间和导入用户
                    //添加两新列，其值为默认值
                    DataColumn dc1 = new DataColumn("LAST_SAVE_TIME", typeof(DateTime));
                    dc1.DefaultValue = DateTime.Now;
                    dc1.AllowDBNull = false;//这在创建表的时候，起作用，在为已有表新增列的时候，不起作用
                    dtImport.Columns.Add(dc1);
                    DataColumn dc2 = new DataColumn("UPDATE_USER", typeof(string));
                    dc2.DefaultValue = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dc2.AllowDBNull = false;
                    dtImport.Columns.Add(dc2);
                    //重新赋值给序号



                    //重新调整导入Table的列名
                    dtImport.Columns["图纸编号"].ColumnName = "DWG_NO";
                    dtImport.Columns["部件编号"].ColumnName = "PART_NO";
                    dtImport.Columns["组简码"].ColumnName = "GROUP_CODE";


                    //批量插入数据库
                    if (BaseBuildSql.ExcuteInsert(dtImport, "IE_Part_Routing"))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("数据导入成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    SplashScreenTool.CloseSplashScreen();

                }
                catch (Exception ex)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
                }
            }

        }
        //导出-默认路径D:\MESTemp
        public override void DoExport(IButtonInfo sender)
        {
            if (string.IsNullOrEmpty(txtProductItem.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请先选择产品类型！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!Directory.Exists(@"D:\MESTemp"))
                Directory.CreateDirectory(@"D:\MESTemp");
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.InitialDirectory = @"D:\MESTemp";//导出默认路径
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";//导出默认格式
            fileDialog.FileName = "MES_TEMP_" + DateTime.Now.ToString("yyMMdd_hhMMss");//导出默认名称
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                //导出表【IE_Part_TaskList】中当前产品类型，无“工艺路线标识”的数据
                DataTable dtList = Common.GetDWG_List.Dwg_List("IE_Part_TaskList T LEFT jOIN IE_Part_MasterData M ON T.PART_NO=M.PART_NO",
                    " T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,T.REF_DWG",
                   " and ISNULL(T.ROUTING_FLAG,'')!='1' and ISNULL(T.UPLOAD_FLAG,'')!='1' and T.PROD_CATEGORY='" + txtProductItem.Text + "' and M.MRP_CONTROLLER not in ('WG1','PG1') ");

                GridControl grid = new GridControl();
                GridView view = new GridView();
                grid.ViewCollection.Add(view);
                grid.MainView = view;
                view.GridControl = grid;
                foreach (DataColumn dc in dtList.Columns)
                {
                    DevExpress.XtraGrid.Columns.GridColumn gridColumnNumber = view.Columns.AddVisible(dc.ColumnName);
                    gridColumnNumber.FieldName = dc.ColumnName;
                }
                grid.DataSource = dtList;
                this.Controls.Add(grid);
                grid.ForceInitialize();
                view.BestFitColumns();
                view.OptionsPrint.PrintHorzLines = false;
                view.OptionsPrint.PrintVertLines = false;
                view.ExportToXlsx(fileDialog.FileName);
                // DevExpress.XtraEditors.XtraMessageBox.Show("导出成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (DevExpress.XtraEditors.XtraMessageBox.Show("导出成功，是否打开文件？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    System.Diagnostics.Process.Start(fileDialog.FileName);//打开指定路径下的文件

            }
        }
        //查询
        public override void DoView(IButtonInfo sender)
        {
            GetRouting();
            gvPart_List_Click(null, null);
        }
        public void GetRouting()
        {
            //SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
            string sql_Pro = txtProductItem.Text.Length > 0 ? " and T.PROD_CATEGORY='" + txtProductItem.Text + "'" : " and T.PROD_CATEGORY like '%%'";
            string sql_DwgNo = txtDWG_No.Text.Length > 0 ? " and T.DWG_NO='" + txtDWG_No.Text + "'" : " and T.DWG_NO like '%%'";
            string sql_PartNo = txtPart_No.Text.Length > 0 ? " and T.PART_NO='" + txtPart_No.Text + "'" : " and T.PART_NO like '%%'";
            string sql = sql_Pro + sql_DwgNo + sql_PartNo;
            dtList = new DataTable();
            dtRouting = new DataTable();
            //获得工艺路线组合表--不同类型工序之间新增一行空行
            string sql_Type = "";
            if (FLAG_TYPE)
                sql_Type = txtProductItem.Text.Length > 0 ? " and PRODUCT_TYPE='" + txtProductItem.Text + "' and ROUTING_TYPE='部件' " : " and PRODUCT_TYPE like '%%' and ROUTING_TYPE='部件'";
            else
                sql_Type = txtProductItem.Text.Length > 0 ? " and PRODUCT_TYPE='" + txtProductItem.Text + "' and ROUTING_TYPE='组件' " : " and PRODUCT_TYPE like '%%' and ROUTING_TYPE='组件'";
            DataTable dtRouting_Temp = Common.GetDWG_List.Dwg_List("IE_Routing_Combination ", "PRODUCT_TYPE,SEQUENCE,GROUP_CODE,ROUTING_DESC", "  " + sql_Type + " order by SEQUENCE");
            RoutingAddNullRow(dtRouting_Temp);
            
            //按部件
            if (FLAG_TYPE)
            {
                //先清空
                gc_Routing_Combina.DataSource = new DataTable();
                gc_CurrentPart.Controls.Clear();
                gc_ReferencePart.Controls.Clear();
                txtProduct_Desc.Text = "";
                txtMODEL_NO.Text = "";
                txtProductFP.Text = "";
                //获取清单列表工艺路线标识不为1的数据
                dtList = Common.GetDWG_List.Dwg_List("IE_Part_TaskList T LEFT jOIN IE_Part_MasterData M ON T.PART_NO=M.PART_NO",
                  "distinct DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,M.MODEL_NO,REF_DWG,M.PRODUCT_ALLOCATION",
                  "  " + sql + " and ISNULL(T.DWG_NO,'')!='NIL' and ISNULL(T.ROUTING_FLAG,'')!='1' and ISNULL(T.DWG_NO,'')!='' and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");
                //获取工艺路线表上载标识不为1的数据
                DataTable dtRouting1 = Common.GetDWG_List.Dwg_List(@"IE_Part_Routing R JOIN IE_Part_TaskList T on R.DWG_NO=T.DWG_NO and R.PART_NO=T.PART_NO JOIN IE_Part_MasterData M ON M.PART_NO=T.PART_NO",
                    "distinct T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,M.MODEL_NO,T.REF_DWG,M.PRODUCT_ALLOCATION",
                    "   " + sql + "  and ISNULL(T.ROUTING_FLAG,'')='1' and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");
                //界面有图纸号不需要查询已存在未上载的号码
                if (txtDWG_No.Text.Length > 0)
                {
                    //合并临时表
                    dtList.Merge(dtRouting1);
                }
                //若有重复项则去掉
                DataView dv = new DataView(dtList);
                DataTable dtResult = dv.ToTable(true, new[] { "DWG_NO", "REF_DWG", "PART_NO" });

                DataTable Dis_Temp1 = dtResult.DefaultView.ToTable(true, new[] { "DWG_NO" });
                DataTable Dis_DWG = dtResult.Clone();
                for (int i = 0; i < Dis_Temp1.Rows.Count; i++)
                {
                    DataRow dr = Dis_DWG.NewRow();
                    dr["DWG_NO"] = Dis_Temp1.Rows[i]["DWG_NO"].ToString();
                    dr["PART_NO"] = dtResult.Select("DWG_NO='" + Dis_Temp1.Rows[i]["DWG_NO"].ToString() + "'").CopyToDataTable().Rows[0]["PART_NO"].ToString();
                    dr["REF_DWG"] = dtResult.Select("DWG_NO='" + Dis_Temp1.Rows[i]["DWG_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_DWG"].ToString();
                    Dis_DWG.Rows.Add(dr);
                }
                gcPart_List.DataSource = Dis_DWG;
            }
            else
            {
                //先清空
                gc_Routing_Combina.DataSource = new DataTable();
                gridControl1.DataSource = new DataTable();
                gridControl2.DataSource = new DataTable();
                txtProduct_Desc.Text = "";
                txtMODEL_NO.Text = "";
                txtProductFP.Text = "";
                dtList = Common.GetDWG_List.Dwg_List("IE_Part_TaskList T LEFT jOIN IE_Part_MasterData M ON T.PART_NO=M.PART_NO",
               "distinct DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,M.MODEL_NO,REF_DWG,REF_MAT,M.PRODUCT_ALLOCATION",
               "  " + sql_PartNo + sql_Pro + "  and ISNULL(T.ROUTING_FLAG,'')!='1' and (ISNULL(T.DWG_NO,'')='' or ISNULL(T.DWG_NO,'')='NIL')  and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");

                //获取工艺路线表上载标识不为1的数据
                DataTable dtRouting1 = Common.GetDWG_List.Dwg_List(@"IE_Part_Routing R JOIN IE_Part_TaskList T on  R.PART_NO=T.PART_NO JOIN IE_Part_MasterData M ON M.PART_NO=T.PART_NO",
                    "distinct T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,M.MODEL_NO,T.REF_DWG,T.REF_MAT,M.PRODUCT_ALLOCATION",
                    "   " + sql_PartNo + sql_Pro + "  and ISNULL(T.ROUTING_FLAG,'')='1' and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");
                if (txtPart_No.Text.Length > 0)
                {
                    //合并临时表
                    dtList.Merge(dtRouting1);
                }
                //若有重复项则去掉
                DataView dv = new DataView(dtList);
                DataTable dtResult = dv.ToTable(true, new[] { "DWG_NO", "REF_DWG", "PART_NO", "REF_MAT" });

                DataTable Dis_Temp1 = dtResult.DefaultView.ToTable(true, new[] { "PART_NO" });
                DataTable Dis_DWG = dtResult.Clone();
                for (int i = 0; i < Dis_Temp1.Rows.Count; i++)
                {
                    DataRow dr = Dis_DWG.NewRow();
                    dr["DWG_NO"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["DWG_NO"].ToString();
                    dr["PART_NO"] = Dis_Temp1.Rows[i]["PART_NO"].ToString();
                    dr["REF_DWG"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_DWG"].ToString();
                    dr["REF_MAT"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_MAT"].ToString();
                    Dis_DWG.Rows.Add(dr);
                }
                gcPart_List.DataSource = Dis_DWG;
            }
            // gcPart_List.DataSource = dtResult;
            //frmGridViewCust.RegisterGrid(gvPart_List);
            //DevStyle.SetGridControlLayout(gcPart_List, false);
           // SplashScreenTool.CloseSplashScreen();
        }
        [DllImport("kernel32.dll")]
        private static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
        //关闭
        private void Frm_IE_Routing_Part_FormClosing(object sender, FormClosingEventArgs e)
        {
            //解除当前用户锁定的图号
            Common.GetLock.UnLock();
            //重新刷新内存
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
            }
        }
        //自动定位至焦点行
        public void GetFoucuseRowHandle(string strDWG_List)
        {
            string searchText = strDWG_List;
            // obtaining the focused view
            ColumnView view = (ColumnView)gc_Routing_Combina.FocusedView;
            // obtaining the column bound to the Country field
            GridColumn column = view.Columns["ROUTING_DESC"];
            if (column != null)
            {
                // locating the row
                //如果用数据源中的列值，请用ColumnView.LocateByValue  LocateByDisplayText
                int rhFound = view.LocateByDisplayText(view.FocusedRowHandle + 1, column, searchText);
                // focusing the cell
                if (rhFound != GridControl.InvalidRowHandle)
                {
                    view.FocusedRowHandle = rhFound;
                    view.FocusedColumn = column;
                }
            }
        }
        public DialogResult ConfirmOK()
        {
            return DevExpress.XtraEditors.XtraMessageBox.Show("当前图纸已维护过部件特征，强制保存将更改同图号所有部件数据，并无法恢复！,是否确认保存？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
        }
        //按部件维护
        private void rbDWG_NO_CheckedChanged(object sender, EventArgs e)
        {
            Check_Changed();
        }
        //按组件维护
        private void rbPART_NO_CheckedChanged(object sender, EventArgs e)
        {
            Check_Changed();
        }
        public void Check_Changed()
        {
            if (rbDWG_NO.Checked)
            {
                FLAG_TYPE = true;
                rbPART_NO.Checked = false;
                Init();
                PART_NO.Visible = false;
                DWG_NO.Visible = true;
                gc_CurrentPart.Visible = true;
                gc_ReferencePart.Visible = true;
                gridControl1.Visible = false;
                gridControl2.Visible = false;
                txtPart_No.Enabled = false;
                txtPart_No.Text = "";
            }
            else
            {
                FLAG_TYPE = false;
                rbDWG_NO.Checked = false;
                Init();
                PART_NO.Visible = true;
                DWG_NO.Visible = false;
                //gc_CurrentPart.Visible = false;
                //gc_ReferencePart.Visible = false;
                gc_CurrentPart.Visible = true;
                gc_ReferencePart.Visible = true;
                gridControl1.Visible = true;
                gridControl1.Dock = DockStyle.Fill;
                // gc_CurrentPart.Controls.Add(gridControl1);
                gridControl2.Visible = true;
                gridControl2.Dock = DockStyle.Fill;
                //gc_ReferencePart.Controls.Add(gridControl2);
                txtPart_No.Enabled = true;
            }
        }
        public DialogResult ConfirmDelete()
        {
            return DevExpress.XtraEditors.XtraMessageBox.Show("上条数据暂未保存，是否保存？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }
        //组件部件切换
        private void btnChange_Click(object sender, EventArgs e)
        {
            int iRow_DWG = gvPart_List.FocusedRowHandle;
            string DWG_No = gvPart_List.GetRowCellDisplayText(iRow_DWG, "DWG_NO").ToString();//标准图纸号
            string Part_No = gvPart_List.GetRowCellDisplayText(iRow_DWG, "PART_NO").ToString();//部件号码
            if (FLAG_TYPE)
            {
                if (DWG_No != "NIL" && DWG_No.Trim().Length > 0)
                {
                    string UpdateSql = @"update IE_Part_TaskList set DWG_NO='NIL',ROUTING_FLAG='',PARM_FLAG='',FEAT_FLAG=''  where DWG_NO='" + DWG_No + "' ";
                    //删除工艺路线和特征特征，以及更新任务清单标识
                    string delete_routing = @" delete FROM [LamexMESManager].[dbo].[IE_Part_Routing] where DWG_NO='" + DWG_No + "' ";
                    string delete_feature = @" delete FROM [LamexMESManager].[dbo].[IE_Part_FeatureList]  where DWG_NO='" + DWG_No + "' ";
                    string delete_size = "delete  FROM [LamexMESManager].[dbo].[IE_Part_SizeParmList] where DWG_NO='" + DWG_No + "' ";
                    BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    BaseBuildSql.ExecuteNonQuery(delete_routing);
                    BaseBuildSql.ExecuteNonQuery(delete_feature);
                    BaseBuildSql.ExecuteNonQuery(delete_size);
                    DevExpress.XtraEditors.XtraMessageBox.Show("部件切换成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (Part_No != "NIL" && Part_No.Trim().Length > 0)
                {
                    string UpdateSql = @"update IE_Part_TaskList set DWG_NO='" + Part_No + "',ROUTING_FLAG='',PARM_FLAG='',FEAT_FLAG=''  where PART_NO='" + Part_No + "' ";
                    string delete_routing = @" delete FROM [LamexMESManager].[dbo].[IE_Part_Routing] where PART_NO='" + Part_No + "' ";
                    string delete_feature = @" delete FROM [LamexMESManager].[dbo].[IE_Part_FeatureList]  where  PART_NO='" + Part_No + "' ";
                    string delete_size = "delete  FROM [LamexMESManager].[dbo].[IE_Part_SizeParmList] where  PART_NO='" + Part_No + "' ";
                    BaseBuildSql.ExecuteNonQuery(UpdateSql);
                    BaseBuildSql.ExecuteNonQuery(delete_routing);
                    BaseBuildSql.ExecuteNonQuery(delete_feature);
                    BaseBuildSql.ExecuteNonQuery(delete_size);
                    DevExpress.XtraEditors.XtraMessageBox.Show("组件切换成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        //工艺路线新增空行方法
        public void RoutingAddNullRow(DataTable dtRouting_Temp)
        {
            dtRouting = dtRouting_Temp.Clone();
            for (int i = 0; i < dtRouting_Temp.Rows.Count; i++)
            {
                DataRow dr = dtRouting.NewRow();
                if (i > 0)
                {
                    if (dtRouting_Temp.Rows[i]["SEQUENCE"].ToString().Substring(0, 2) !=
                        dtRouting_Temp.Rows[i - 1]["SEQUENCE"].ToString().Substring(0, 2))
                    {
                        dr["PRODUCT_TYPE"] = "";
                        dr["SEQUENCE"] = "";
                        dr["GROUP_CODE"] = "";
                        dr["ROUTING_DESC"] = "";
                        dtRouting.Rows.Add(dr);
                        DataRow dr1 = dtRouting.NewRow();
                        dr1["PRODUCT_TYPE"] = dtRouting_Temp.Rows[i]["PRODUCT_TYPE"].ToString();
                        dr1["SEQUENCE"] = dtRouting_Temp.Rows[i]["SEQUENCE"].ToString();
                        dr1["GROUP_CODE"] = dtRouting_Temp.Rows[i]["GROUP_CODE"].ToString();
                        dr1["ROUTING_DESC"] = dtRouting_Temp.Rows[i]["ROUTING_DESC"].ToString();
                        dtRouting.Rows.Add(dr1);
                    }
                    else
                    {
                        dr["PRODUCT_TYPE"] = dtRouting_Temp.Rows[i]["PRODUCT_TYPE"].ToString();
                        dr["SEQUENCE"] = dtRouting_Temp.Rows[i]["SEQUENCE"].ToString();
                        dr["GROUP_CODE"] = dtRouting_Temp.Rows[i]["GROUP_CODE"].ToString();
                        dr["ROUTING_DESC"] = dtRouting_Temp.Rows[i]["ROUTING_DESC"].ToString();
                        dtRouting.Rows.Add(dr);
                    }
                }
                else
                {
                    dr["PRODUCT_TYPE"] = dtRouting_Temp.Rows[i]["PRODUCT_TYPE"].ToString();
                    dr["SEQUENCE"] = dtRouting_Temp.Rows[i]["SEQUENCE"].ToString();
                    dr["GROUP_CODE"] = dtRouting_Temp.Rows[i]["GROUP_CODE"].ToString();
                    dr["ROUTING_DESC"] = dtRouting_Temp.Rows[i]["ROUTING_DESC"].ToString();
                    dtRouting.Rows.Add(dr);
                }
            }
        }
        //BOM版本
        public DataTable GetBOMVer()
        {
            DataTable dt = new DataTable();
            string sql = @"select DISTINCT ISNULL(ltrim(rtrim(Version)),'') AS Version from [dbo].[B_IE_PACKAGE_MASTER_DATA_STD]
  ORDER BY Version DESC";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        public void DateEditFormat()
        {
            cbBOM.Properties.Items.Clear();
            foreach (DataRow row in GetBOMVer().Rows)
            {
                cbBOM.Properties.Items.Add(row["Version"]);
            }
            cbBOM.SelectedIndex = 0;
        }

        private void gvPart_List_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(gvPart_List.GetFocusedRowCellValue(gvPart_List.FocusedColumn));
                e.Handled = true;
            }
        }
    }
}
